package com.dalao.root.custom.service.impl;

import com.dalao.root.custom.entity.CusField;
import com.dalao.root.custom.entity.CusTable;
import com.dalao.root.custom.entity.CusWhere;
import com.dalao.root.custom.mapper.DataMapper;
import com.dalao.root.custom.service.CustomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CustomServiceImpl extends CustomService {
    @Autowired
    private DataMapper dataMapper;

    @Override
    public Integer insertData(String table, Map<String, String> data) {
        try {
            return dataMapper.insertData(table,data);
        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean deleteData(String table, List<Map<String,String>> where) {
        try {
            dataMapper.deleteData(table,where);
            return true;
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return false;
    }

    @Override
    public boolean updateData(String table, Map<String, String> data, List<Map<String,String>> where) {
        try {
            dataMapper.updateData(table,data,where);
            return true;
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return false;
    }

    @Override
    public Object selectData(String table, List<CusField> field, List<Map<String,String>> where) {
        try {
            return dataMapper.selectData(table,field,where);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return null;
    }

    @Override
    public List<Object> selectDataList(String table, List<CusField> field, List<Map<String, String>> where) {
        try {
            return dataMapper.selectDataList(table,field,where);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return null;
    }
}
